package view.screen;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import view.base.ListScreen;
import base.ScreenActionListener;
import controller.Controller;

public final class ContactsScreen extends ListScreen {
	private final boolean fromDB;

	public ContactsScreen(ScreenActionListener controller, String[] contacts, boolean fromDB){
		super(controller, "Contacts", List.EXCLUSIVE, contacts);

		this.fromDB = fromDB;

		this.addCommand(new Command("Connect", Command.OK, 1));
		
		if(fromDB)
			this.addCommand(new Command("Remove", Command.OK, 1));
		else
			this.addCommand(new Command("Add", Command.OK, 1));
		

		this.setCommandListener(this);
	}

	public void commandAction(Command c, Displayable d) {
		int id = this.getSelectedIndex();
		switch (c.getCommandType()) {
		case Command.OK:
			if(c.getLabel().equals("Connect"))
				controller.viewAction(Controller.CONNECT_COMMAND, new Integer(id));
			else
				if(fromDB)
					controller.viewAction(Controller.REMOVE_COMMAND, new Integer(id));
				else
					controller.viewAction(Controller.ADD_COMMAND, new Integer(id));
			break;
		default:
			super.commandAction(c, d);
			break;

		}
	}
}
